#include "results_document.h"

ResultsDocument::ResultsDocument(QObject *parent) : QTextDocument( parent ) {
    _treeWidgetItem = new QTreeWidgetItem();
    _timeStamp = new QDateTime(QDate::currentDate(),QTime::currentTime());
}


void ResultsDocument::appendHeader(QString msg){
    _content += QString("<h1>%1</h1>").arg(msg);
    setContent();
}

void ResultsDocument::appendSubHeader(QString msg){
    _content += QString("<h2>%1</h2>").arg(msg);
    setContent();
}

void ResultsDocument::appendText(QString msg) {
    _content += QString("<p>%1</p>").arg(msg);
    setContent();
}

void ResultsDocument::appendTable(QList<QStringList> contents, bool colHeader, bool rowHeader) {
    _content += "<table>";
    for(int i=0;i<contents.count();i++){
        QStringList row = contents[i];
        _content += "<tr>\n";
        for(int j=0;j<row.count();j++){
            if( (!i && colHeader ) || (!j && rowHeader ) )
                _content += QString("<th>%1</th>").arg(row[j]);
            else
                _content += QString("<td>%1</td>").arg(row[j]);
        }
        _content += "</tr>\n";
    }
    _content += "</table>";
    setContent();
}


void ResultsDocument::appendList(QStringList list, bool ordered){
    _content += ordered ? "<ol>" : "<ul>";

    foreach(QString row, list )
        _content += QString("<li>%1</li>").arg(row);

    _content += ordered ? "</ol>" : "</ul>";
    setContent();
}


void ResultsDocument::setContent() {
    QString html = QString("<html><body>%1</body></html>").arg(_content);
    setHtml( html );
}



